import java.util.Scanner;

public class Demo1 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        while(scan.hasNextLine()) {
            String str1 = scan.nextLine();
            String str2 = scan.nextLine();

            System.out.println(func(str1,str2));
        }

    }

    public static boolean func(String str1, String str2) {
        char[] ch = str1.toCharArray();
        char[] cs = str2.toCharArray();
        int m = ch.length;
        int n = cs.length;

        boolean[][] dp = new boolean[n+1][m+1];

        dp[0][0] = true;
        for(int i = 0; i <= n; i++) {
            for(int j = 1; j <= m; j++) {
                if(ch[j-1] == '*') {
                    if(i == 0) {
                        dp[i][j] = dp[i][j-1];
                    }else {
                        if(cs[i-1] == '.'||(cs[i-1] >= 'a' && cs[i-1] <= 'z')||(cs[i-1] >= 'A' && cs[i-1] <= 'Z') || (cs[i-1] >= '0' && cs[i-1] <= '9')) {
                            dp[i][j] = dp[i-1][j] || dp[i][j-1];
                        }
                    }
                }else {

                    if(i > 0 && fund(ch[j-1],cs[i-1])) {
                        dp[i][j] = dp[i-1][j-1];
                    }
                }
            }
        }

        return dp[n][m];
    }

    public static boolean fund(char ch,char cs) {
        if(ch == '?') return true;
        if(ch >='a' && ch <='z') {
            ch =(char) (ch - 'a' + 'A');
        }

        if(cs >='a' && cs <='z') {
            cs =(char) (cs - 'a' + 'A');
        }

        return ch == cs;
    }
}
